package com.hanamaki.demo02.paramter;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class FireFoxDriverTestNg {

    /**
     * 1. 依赖(jar包)的添加
     * 2. 下载想要驱动的浏览器的驱动，并且放在了对应的浏览器的根目录下
     * 3. 编写脚本
     */
    WebDriver driver;

    @BeforeClass
    @Parameters("Browser")
    public void setup(String Browser) {
        if (Browser.equalsIgnoreCase("firefox")) {
            // 注册驱动的位置
            System.setProperty("webdriver.gecko.driver", "C:\\Program Files\\Mozilla Firefox\\geckodriver.exe");
//        实例化驱动
            driver = new FirefoxDriver();
        }
        if (Browser.equalsIgnoreCase("chrome")) {
            System.setProperty("webdriver.chrome.driver", "C:\\Program Files\\Google\\Chrome\\Application\\chromedriver.exe");

            driver = new ChromeDriver();
        }
    }

    @Test
    public void test() {
        driver.get("https://www.baidu.com");

//        定位元素
        WebElement element = driver.findElement(By.xpath("//input[@id='kw']"));
        element.sendKeys("selenium");

        WebElement element1 = driver.findElement(By.xpath("//input[@value='百度一下']"));
        element1.click();

    }

    @AfterClass
    public void close() {
        //        关闭浏览器
//        driver.close();
    }


}
